<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>form</title>
    <script type="text/javascript">
      function getForm() {
        document.write(document.forms[0].a.value);
      }
    </script>


    <!-- 方法二： -->
    <!-- <script type="text/javascript">
        var x=document.getElementById("myForm");
        for (var i=0;i<x.length;i++)
        {
        document.write(x.elements[i].value);
        document.write("<br />");
        document.write(x.elements[i].type);
        document.write("<br />");
        }
    </script> -->
</head>
<body>
  <!--onsubmit 表单提交之前会调用函数  -->
    <form id="form1" name="form1" action="" method="post" onsubmit="getForm()">
        <input type="text" id="a" value="abc">
        <input type="submit" value="ok">
    </form>


    <!-- 方法二： -->
    <!-- <form id="myForm">
        Firstname: <input id="fname" type="text" value="Mickey" />
        Lastname: <input id="lname" type="text" value="Mouse" />
        <input id="sub" type="button" value="Submit" />
    </form> -->


</body>
</html>